#ifndef BLOCKGROUP_H
#define BLOCKGROUP_H

#include <QObject>
#include <QVector>

#include "FileSystem.h"

class BlockGroup : public QObject
{
    Q_OBJECT
public:
    explicit BlockGroup(QObject *parent = 0);
	BlockGroup(const int& number, const int& totalBlocks, const int& totalINodes, QObject *parent = 0);

	/**
	 * @return Number of this group.
	 */
	int getGroupNumber() const {
		return groupNumber_;
	}

	/**
	 * @return Number of free i-nodes available in this group.
	 */
	int getFreeINodes() const {
		return freeINodes_;
	}

	/**
	 * @return Number of free blocks available in this group.
	 */
	int getFreeBlocks() const {
		return freeBlocks_;
	}

	/**
	 * @return Number of blocks in this group.
	 */
	int getTotalBlocks() const {
		return totalBlocks_;
	}

	/**
	 * @return Number of i-nodes in this group.
	 */
	int getTotalINodes() const {
		return totalINodes_;
	}

//////////////////////////////////////////////////////////////////////
//
//		File operations section
//
//////////////////////////////////////////////////////////////////////

	int getGroupOffset();

	/**
	 * Reads a group's descriptor from FileSystem. Must be called before any other operations
	 * on this group.
	 * @param fileSystem A file containing filesystem data from which a descriptor will be read.
	 */
	void readBlockDescriptor( QFile* fileSystem );

	/**
	 * Reads and analyzes this block's block bitmap.
	 * @param fileSystem A file containing filesystem data in which this group resides.
	 */
	void readBlockStructure( QFile* fileSystem );

	/**
	 * Reads and analyzes this block's I-Node bitmap.
	 * @param fileSystem A file containing filesystem data in which this group resides.
	 */
	void readINodeStructure( QFile* fileSystem );

signals:

public slots:


private:
	int groupNumber_;
	int totalBlocks_;
	int totalINodes_;
	int freeBlocks_;
	int freeINodes_;

	/** Contains an absolute number of the first block of this group's block bitmap. */
	unsigned int blockBitmap_;
	/** Contains an absolute number of the first block of this group's I-Node bitmap. */
	unsigned int iNodeBitmap_;

	QVector<bool> bitmap_;
};

#endif // BLOCKGROUP_H
